package com.shudingke.utils;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2//开启swagger注解支持

@Configuration
public class ConfigCenter implements WebMvcConfigurer {
    @Bean
    public Docket docketApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //选择对于那些包生成API文档
                .select()
                //所有包
                .apis(RequestHandlerSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("HRMS系统接口文档")
                .description("软帝集团S-HRMS系统，接口地址介绍，包含XXX，XXX模块")
                .version("v1.0")
                .license("服务条款")
                .licenseUrl("http://www.softeem.com")
                .contact(new Contact("MRChai","http://www.softeem.top","XXXXX@sina.com"))
                .build();
    }
    
    
    
    


    @Bean
    public MybatisPlusInterceptor getPage(){
        //配置mybatisplus分页
        PaginationInnerInterceptor pages = new PaginationInnerInterceptor();
        
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        
        interceptor.addInnerInterceptor(pages);

        //防止全部更新 全部删除
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        
        return interceptor;
    }
}
